package org.maverickjs.persistence;

import java.util.List;

import org.maverick.persistence.simple.jpa.GenericDAO;
import org.maverickjs.model.bean.UserJB;
import org.maverickjs.persistence.dao.UserDAO;

public class UserDAOImpl extends GenericDAO<UserJB> implements UserDAO {

	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unchecked")
	@Override
	public UserJB login(String userName, String password) {
		List<UserJB> list = super.entityManager
								 .createQuery(" select user from UserJB user where user.userName = :userName and user.password = :password ")
								 .setParameter("userName", userName)
								 .setParameter("password", password)
								 .getResultList();
		return (list != null && !list.isEmpty()) ? list.get(0) : null;
	}

}
